home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / compugr.zip / SUBGRAPH.INC < prev   
Text File  |  1992-08-20  |  1KB  |  45 lines

  1. function achievable( var graph : sectorArray;
  2.                          start : sector;
  3.                      var subgr : sectorSet ) : sectorindex;
  4.  
  5. { compute connected subgraph leaving start; return number of adjacent
  6.   sectors as value of function }
  7. var
  8.   si : sectorIndex;
  9.   wi : invIndex;
  10.   breadth : queue;
  11.   s,
  12.   daddy, sonny : sector;
  13.   count : sectorindex;
  14.   i : warpindex;
  15.   d : distanceArray;
  16. begin
  17.   for s := 1 to maxSector do
  18.     begin
  19.       D[s].d := -1;
  20.       subgr[ s ] := false;
  21.     end; {for}
  22.   breadth.front := 0;
  23.   enqueue( breadth, start, start );
  24.   subgr[start] := true;
  25.   while breadth.front > 0 do
  26.     begin
  27.       serve( breadth, daddy, sonny );
  28.       if D[ sonny ].d = -1 then {haven't hit him before:}
  29.         begin
  30.           D[ sonny ].d := D[ daddy ].d + 1;
  31.           D[ sonny ].s := daddy;
  32.           with graph[ sonny ] do if number > 0 then
  33.             if (graph[sonny].etc and avoid) = Nothing then
  34.               for wi := 1 to number do
  35.                 if not subgr[ data[wi] ] then
  36.                   begin
  37.                     enqueue( breadth, sonny, data[ wi ] );
  38.                     subgr[ data[wi] ] := true;
  39.                   end; {if with for if}
  40.         end; {if}
  41.     end; {while}
  42.   count := 0;
  43.   for s := 1 to maxSector do if subgr[s] then inc( count );
  44.   achievable := count;
  45. end;